package com.usts2022.classcostrecord;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;


public class LoginActivity extends AppCompatActivity {
    private static final String TAG = "LoginActivity";
    private Button mRegister,mLogin;
    private EditText mAccount,mPassword;
    private RadioGroup loginRg;
    private FragmentManager fm;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        //打开fragment
        fm = getSupportFragmentManager();
        LoginFragment loginFragment = new LoginFragment();
        fm.beginTransaction().add(R.id.my_fragment, loginFragment).commitAllowingStateLoss();
        //绑定
        loginRg = findViewById(R.id.rg_login);


        //改变事件
        loginRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
                for (int i = 0; i < loginRg.getChildCount(); i++) {
                    RadioButton rb = (RadioButton) radioGroup.getChildAt(i);
                    if (rb.isChecked()) {
                        changeRb(i);
                        break;
                    }
                }
            }
        });
    }

        //登录注册切换按钮
        private void changeRb ( int i){
            switch (i) {
                case 0:
                    LoginFragment lf = new LoginFragment();
                    fm.beginTransaction().replace(R.id.my_fragment, lf).commitAllowingStateLoss();
                    break;
                case 1:
                    RegisterFragment registerFragment = new RegisterFragment();
                    fm.beginTransaction().replace(R.id.my_fragment, registerFragment).commitAllowingStateLoss();
                    break;
            }
        }



}